<template>
  <el-dialog
    :title="!dataForm.exhibitionId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="展览编号" prop="exhibitionNo">
      <el-input v-model="dataForm.exhibitionNo" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="展览名称" prop="exhibitionName">
      <el-input v-model="dataForm.exhibitionName" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="开放时间" prop="openTime">
      <el-input v-model="dataForm.openTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="主体照片" prop="bodyPhoto">
      <el-input v-model="dataForm.bodyPhoto" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="详情图片" prop="detailPhoto">
      <el-input v-model="dataForm.detailPhoto" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="主办方" prop="organizer">
      <el-input v-model="dataForm.organizer" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="展览地址" prop="address">
      <el-input v-model="dataForm.address" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="展览收费" prop="cost">
      <el-input v-model="dataForm.cost" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="展览商品" prop="goods">
      <el-input v-model="dataForm.goods" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="展览提示" prop="notice">
      <el-input v-model="dataForm.notice" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="展览详情" prop="details">
      <el-input v-model="dataForm.details" placeholder=""></el-input>
    </el-form-item>
    <!-- <el-form-item label="" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder=""></el-input>
    </el-form-item> -->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
// import axios from 'axios'
import { getExhibitionById, saveOrUpdateExhibition } from '@/api/exhibition'
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        exhibitionNo: '',
        exhibitionId: '',
        exhibitionName: '',
        openTime: '',
        bodyPhoto: '',
        detailPhoto: '',
        organizer: '',
        address: '',
        cost: '',
        goods: '',
        notice: '',
        details: '',
        createTime: '',
        updateTime: ''
      },
      dataRule: {
        exhibitionId: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        exhibitionName: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        openTime: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        bodyPhoto: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        detailPhoto: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        organizer: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        cost: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        goods: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        notice: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        details: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        updateTime: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init (id) {
      // alert('初始化')
      this.dataForm.exhibitionId = id || 0
      this.visible = true
      this.$nextTick(async () => {
        this.$refs.dataForm.resetFields()
        if (this.dataForm.exhibitionId) {
          const { data } = await getExhibitionById(this.dataForm.exhibitionId)
          if (data && data.code === 0) {
            this.dataForm.exhibitionNo = data.exhibition.exhibitionNo
            this.dataForm.exhibitionName = data.exhibition.exhibitionName
            this.dataForm.openTime = data.exhibition.openTime
            this.dataForm.bodyPhoto = data.exhibition.bodyPhoto
            this.dataForm.detailPhoto = data.exhibition.detailPhoto
            this.dataForm.organizer = data.exhibition.organizer
            this.dataForm.address = data.exhibition.address
            this.dataForm.cost = data.exhibition.cost
            this.dataForm.goods = data.exhibition.goods
            this.dataForm.notice = data.exhibition.notice
            this.dataForm.details = data.exhibition.details
            this.dataForm.createTime = data.exhibition.createTime
            this.dataForm.updateTime = data.exhibition.updateTime
          }
          // this.$http({
          //   url: `/exhibition/info/${this.dataForm.exhibitionId}`,
          //   method: 'get'
          //   // params: this.$http.adornParams()
          // }).then(({ data }) => {
          //   if (data && data.code === 0) {
          //     this.dataForm.exhibitionId = data.exhibition.exhibitionId
          //     this.dataForm.exhibitionName = data.exhibition.exhibitionName
          //     this.dataForm.openTime = data.exhibition.openTime
          //     this.dataForm.bodyPhoto = data.exhibition.bodyPhoto
          //     this.dataForm.detailPhoto = data.exhibition.detailPhoto
          //     this.dataForm.organizer = data.exhibition.organizer
          //     this.dataForm.address = data.exhibition.address
          //     this.dataForm.cost = data.exhibition.cost
          //     this.dataForm.goods = data.exhibition.goods
          //     this.dataForm.notice = data.exhibition.notice
          //     this.dataForm.details = data.exhibition.details
          //     this.dataForm.createTime = data.exhibition.createTime
          //     this.dataForm.updateTime = data.exhibition.updateTime
          //   }
          // })
        }
      })
    },
    // 表单提交
    dataFormSubmit () {
      this.$refs.dataForm.validate(async (valid) => {
        if (valid) {
          const exhibition = {
            exhibitionNo: this.dataForm.exhibitionNo || undefined,
            exhibitionId: this.dataForm.exhibitionId,
            exhibitionName: this.dataForm.exhibitionName,
            openTime: this.dataForm.openTime,
            bodyPhoto: this.dataForm.bodyPhoto,
            detailPhoto: this.dataForm.detailPhoto,
            organizer: this.dataForm.organizer,
            address: this.dataForm.address,
            cost: this.dataForm.cost,
            goods: this.dataForm.goods,
            notice: this.dataForm.notice,
            details: this.dataForm.details
            // createTime: this.dataForm.createTime,
            // updateTime: this.dataForm.updateTime
          }
          const { data } = await saveOrUpdateExhibition(this.dataForm.exhibitionId, exhibition)
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          } else {
            this.$message.error(data.msg)
          }

          // axios(`/exhibition/${!this.dataForm.exhibitionId ? 'save' : 'update'}`, {
          //   method: 'post',
          //   data: {
          //     exhibitionNo: this.dataForm.exhibitionNo || undefined,
          //     exhibitionId: this.dataForm.exhibitionId,
          //     exhibitionName: this.dataForm.exhibitionName,
          //     openTime: this.dataForm.openTime,
          //     bodyPhoto: this.dataForm.bodyPhoto,
          //     detailPhoto: this.dataForm.detailPhoto,
          //     organizer: this.dataForm.organizer,
          //     address: this.dataForm.address,
          //     cost: this.dataForm.cost,
          //     goods: this.dataForm.goods,
          //     notice: this.dataForm.notice,
          //     details: this.dataForm.details
          //     // createTime: this.dataForm.createTime,
          //     // updateTime: this.dataForm.updateTime
          //   }
          // }).then(({ data }) => {
          //   if (data && data.code === 0) {
          //     this.$message({
          //       message: '操作成功',
          //       type: 'success',
          //       duration: 1500,
          //       onClose: () => {
          //         this.visible = false
          //         this.$emit('refreshDataList')
          //       }
          //     })
          //   } else {
          //     this.$message.error(data.msg)
          //   }
          // })
        }
      })
    }
  }
}
</script>
